package com.bubblegumproject.ogo.swing.events;

import javax.swing.*;
import java.awt.event.WindowListener;
import java.awt.event.WindowEvent;

/**
 * Condition that's triggered when a JFrame is closed.
 *
 * @author Azubuko Obele (buko.obele@gmail.com)
 */
public class FrameClosedCondition extends AbstractCondition {

    public FrameClosedCondition(JFrame frame) {
        assert(frame != null);
        frame.addWindowListener(new WindowListener() {
            public void windowOpened(WindowEvent e) {}
            public void windowClosing(WindowEvent e) {
                occured();
            }

            public void windowIconified(WindowEvent e) {}
            public void windowDeiconified(WindowEvent e) {}
            public void windowActivated(WindowEvent e) {}
            public void windowDeactivated(WindowEvent e) {}

            public void windowClosed(WindowEvent e) {}
        });
    }

    public static FrameClosedCondition FrameClosed(JFrame frame) {
        return new FrameClosedCondition(frame);
    }
}
